﻿using System;
using System.Runtime.InteropServices;

namespace Labthink.PCSoft.UniversalHost4.Utility
{
    public static class Shell
    {
        [DllImport("kernel32.dll")]
        public static extern bool AllocConsole();
        [DllImport("kernel32.dll")]
        public static extern bool FreeConsole();

        static Shell()
        {
//#if DEBUG
//            AllocConsole();
//#endif
        }

        /// <summary>  
        /// 输出信息  
        /// </summary>  
        /// <param name="format"></param>  
        /// <param name="args"></param>  
        public static void WriteLine(string format, params object[] args)
        {
//#if DEBUG
//            WriteLine(string.Format(format, args));
//#endif
        }

        public static void WriteLine(ConsoleColor color, string format, params object[] args)
        {
//#if DEBUG
//            WriteLine(color,string.Format(format, args));
//#endif
        }

        /// <summary>  
        /// 输出信息  
        /// </summary>  
        /// <param name="output"></param>  
        public static void WriteLine(string output)
        {
//#if DEBUG
//            Console.ForegroundColor = GetConsoleColor(output);
//            Console.WriteLine(@"[{0}]  {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), output);
//#endif
        }

        public static void WriteLine(ConsoleColor color,string output)
        {
           
//#if DEBUG
//            Console.ForegroundColor = color;
//            Console.WriteLine(@"[{0}]  {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), output);
//#endif
        }

        /// <summary>  
        /// 根据输出文本选择控制台文字颜色  
        /// </summary>  
        /// <param name="output"></param>  
        /// <returns></returns>  
        private static ConsoleColor GetConsoleColor(string output)
        {
            if (output.StartsWith("警告")) return ConsoleColor.Yellow;
            if (output.StartsWith("错误")) return ConsoleColor.Red;
            if (output.StartsWith("注意")) return ConsoleColor.Green;
            return ConsoleColor.Gray;
        }
    }
}
